package com.queclink.ycm.entity.data;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.queclink.ycm.common.utils.HexUtils;

import java.text.DecimalFormat;

/**
 * @author jim.li
 * @email jim.li@queclink.com
 * @date 2021-12-24 17:30:00
 */
public class Data82 extends Data {

    private String SignalStrengthLevel;
    private String FixState;
    private String FixMode;
    private String Longitude;
    private String Latitude;
    private String UTC;
    private String Speed;
    private String HDOP;
    private String Azimuth;
    private String Altitude;
    private String SatelliteCount;

    public Data82() {
    }

    @JSONField(
            name = "SignalStrengthLevel"
    )
    public String getSignalStrengthLevel(JSONObject jsonObject) {
        return this.SignalStrengthLevel;
    }

    @JSONField(
            name = "HDOP"
    )
    public String getHDOP(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Double hdop = jsonObject.getDouble("HDOP");
        String format = new DecimalFormat("0.0").format(hdop);
        String replace = format.replace(".", "");
        String s = HexUtils.intToHex(Integer.valueOf(replace), 2);
        sb.append(s);
        return sb.toString();
    }

    public void setHDOP(String hDOP) {
        this.HDOP = hDOP;
    }

    @JSONField(
            name = "Azimuth"
    )
    public String getAzimuth(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Integer azimuth = jsonObject.getInteger("Azimuth");
        String s = HexUtils.intToHex(azimuth, 4);
        sb.append(s);
        return sb.toString();
    }

    public void setAzimuth(String azimuth) {
        this.Azimuth = azimuth;
    }

    @JSONField(
            name = "Altitude"
    )
    public String getAltitude(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Double altitude = jsonObject.getDouble("Altitude");
        String format = new DecimalFormat("0.0").format(altitude);
        String replace = format.replace(".", "");
        String s = HexUtils.intToHex(Integer.valueOf(replace), 6);
        sb.append(s);
        return sb.toString();
    }

    public void setAltitude(String altitude) {
        this.Altitude = altitude;
    }

    @JSONField(
            name = "SatelliteCount"
    )
    public String getSatelliteCount(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Integer satelliteCount = jsonObject.getInteger("SatelliteCount");
        String s = HexUtils.intToHex(satelliteCount, 2);
        sb.append(s);
        return sb.toString();
    }

    public void setSatelliteCount(String satelliteCount) {
        this.SatelliteCount = satelliteCount;
    }

    @JSONField(
            name = "FixState"
    )
    public String getFixState() {
        return this.FixState;
    }

    public void setFixState(String fixState) {
        this.FixState = fixState;
    }

    @JSONField(
            name = "FixMode"
    )
    public String getFixMode() {
        return this.FixMode;
    }

    public void setFixMode(String fixMode) {
        this.FixMode = fixMode;
    }

    @JSONField(
            name = "Longitude"
    )
    public String getLongitude(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Double longitude = jsonObject.getDouble("Longitude");
        String format = new DecimalFormat("0.000000").format(longitude);
        String replace = format.replace(".", "");
        String lng = HexUtils.LongStrToHex(replace, 8);
        sb.append(lng);
        return sb.toString();
    }

    public void setLongitude(String longitude) {
        this.Longitude = longitude;
    }

    @JSONField(
            name = "Latitude"
    )
    public String getLatitude(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Double latitude = jsonObject.getDouble("Latitude");
        String format = new DecimalFormat("0.000000").format(latitude);
        String replace = format.replace(".", "");
        String lat = HexUtils.LongStrToHex(replace, 8);
        sb.append(lat);
        return sb.toString();
    }

    public void setLatitude(String latitude) {
        this.Latitude = latitude;
    }

    @JSONField(
            name = "UTC"
    )
    public String getUTC(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        String utcTime = jsonObject.getString("UTC");
        String s = HexUtils.LongStrToHex(utcTime, 8);
        sb.append(s);
        return sb.toString();
    }

    public void setUTC(String UTC) {
        this.UTC = UTC;
    }

    @JSONField(
            name = "Speed"
    )
    public String getSpeed(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Double speed = jsonObject.getDouble("Speed");
        String format = new DecimalFormat("0.0").format(speed);
        String replace = format.replace(".", "");
        String s = HexUtils.intToHex(Integer.valueOf(replace), 4);
        sb.append(s);
        return sb.toString();
    }

    public void setSpeed(String speed) {
        this.Speed = speed;
    }

    public String getFixState_FixMode(JSONObject jsonObject) {
        Integer SignalStrengthLevel = jsonObject.getInteger("SignalStrengthLevel");
        Integer fixState = jsonObject.getInteger("FixState");
        Integer fixMode = jsonObject.getInteger("FixMode");
        Integer total = SignalStrengthLevel * 16 + fixState * 4 + fixMode;
        String s = HexUtils.intToHex(total, 2);
        return s;
    }

    public String getDataID() {
        // data82
        return HexUtils.intToHex(82, 2);
    }

    public String getLength() {
        return "16";
    }

    @Override
    public String combine(JSONObject jsonObject) throws Exception {
        StringBuffer sb = new StringBuffer();
        sb.append(this.getDataID());
        sb.append(this.getLength());
        sb.append(this.getFixState_FixMode(jsonObject));
        sb.append(this.getLongitude(jsonObject));
        sb.append(this.getLatitude(jsonObject));
        sb.append(this.getUTC(jsonObject));
        sb.append(this.getSpeed(jsonObject));
        sb.append(this.getHDOP(jsonObject));
        sb.append(this.getAzimuth(jsonObject));
        sb.append(this.getAltitude(jsonObject));
        sb.append(this.getSatelliteCount(jsonObject));
        return sb.toString();
    }

    public String combine82(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        sb.append(this.getFixState_FixMode(jsonObject));
        sb.append(this.getLongitude(jsonObject));
        sb.append(this.getLatitude(jsonObject));
        sb.append(this.getUTC(jsonObject));
        sb.append(this.getSpeed(jsonObject));
        sb.append(this.getHDOP(jsonObject));
        sb.append(this.getAzimuth(jsonObject));
        sb.append(this.getAltitude(jsonObject));
        sb.append(this.getSatelliteCount(jsonObject));
        return sb.toString();
    }
}
